<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class File_image_Model extends CI_Model{
    function __construct()
    {
        parent::__construct();
    }
    function getAllData($num,$offset){
        $query = $this->db->get('file_image',$num,$offset);
      
        return $query->result();  
    } 
     function get_object($id)
    {
        $query = $this->db->get_where('file_image', array('file_image_id' =>$id));
        return $query->row();
    }
    function getNumData(){
        $query = $this->db->get('file_image');
        return $query->num_rows();
    }
    function delete($id){
          $this->db->where('file_image_id',$id);
          $query = $this->db->delete('file_image');
          if($query){
              return true;
          }else{
              return false;
          }
    }
	function deleted($id){
          $this->db->where('file_image_id',$id);
		  $data=array('bl_active'=>'-1');
          $query = $this->db->update('file_image',$data);
          if($query){
              return true;
          }else{
              return false;
          }
    }
    function get_list_permit(){
        return $this->db->get('permission')->result();
    }
   
   function saveData($file_image_id,$data){
             if($file_image_id!=0){
                    $this->db->where('file_image_id',$file_image_id);
                    if($this->db->update('file_image',$data)){
                         return true;
                    }else{
                         return false;
                    }
             }else{
                    if($this->db->insert('file_image',$data)){
                        return true;
                        
                    }else{
                        return false;
                    }
            }
    }
    function get_num_data($arr_search){
        /*Begin search*/
        switch($arr_search['field_search'])
        {
            case 'title':
                $this->db->like('title',$arr_search['key_search']);
            break ;
        }
        /*End search*/
        $this->db->select('file_image.*,file_image_cat.name');
        $this->db->join('file_image_cat','file_image.file_image_cat_code = file_image_cat.code');
        
        $this->db->where('bl_active <>',-1);
        $query = $this->db->get('file_image');
        return $query->num_rows();
    }
    function get_all_data($num,$offset,$arr_search)
    {
        /*Begin search*/
        switch($arr_search['field_search'])
        {
            case 'title':
                $this->db->like('title',$arr_search['key_search']);
            break ;
        }
        /*End search*/
        $this->db->select('file_image.*,file_image_cat.name');
        $this->db->join('file_image_cat','file_image.file_image_cat_code = file_image_cat.code');
        
        $this->db->where('bl_active <> ',-1);
        $this->db->order_by('dt_create','DESC');
        $query = $this->db->get('file_image',$num,$offset);
        return $query->result();
    }   
   function get_file_extension($file_name) {
		return substr(strrchr($file_name,'.'),1);
	}
    function getAllImageCat(){
       $query = $this->db->get('file_image_cat');
       return $query->result();
    }
    
  }
?>
